<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/*****
 * Author: Dan Olsen
 * Version: 0.1.1
 * $Rev: 10 $
 * $Date: 2010-01-06 23:09:14 +0000 (Wed, 06 Jan 2010) $
 */

class ErrorStack {
	var $_url = "http://www.errorstack.com/submit";
	var $ci;
	var $_key;
	var $_return_type;

	function ErrorStack() {
		$this->ci =& get_instance();
		$this->ci->load->config('error_stack');
		$this->_key = $this->ci->config->item('Error_Stack_key');
		$this->_return_type = $this->ci->config->item('Error_Stack_return_type');
	}

	function send_error($values = array(), $error_stack_key = false, $return_type = false) {
		if ($error_stack_key) {
			$query_string = "_s=$error_stack_key&";
		} else {
			$query_string = "_s=$this->_key&";
		}

		if ($return_type) {
			$query_string .= "_r$return_type&";
		} else {
			$query_string .= "_r$this->_return_type&";
		}
		
		foreach ($this->ci->config->item('Error_Stack_default_params') as $key => $value) {
			$query_string .= "$key=" . urlencode($value) . "&";
		}

		foreach ($values as $key => $value) {
			$query_string .= "$key=" . urlencode($value) . "&";
		}

		$url = "$this->_url?$query_string";
		
		$ch = curl_init($this->_url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);

		return $output;
	}
}



?>